using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Box2D.Net.Collision.Shapes;
using Box2D.Net.Dynamics.Bodies;
using Box2D.Net.Dynamics.Fixtures;
using Box2D.Net.Dynamics.Joints;
using Box2D.Net.Dynamics.Joints.Distance;
using Box2D.Net.Dynamics.World;

namespace Box2D.WorldTests
{
    [ExcludeFromCodeCoverage]
    public class DistanceJointProblemWorld
    {
        public static World CreateWorld()
        {
            // Vector2 g(0.000000000000000e+00f, -1.000000000000000e+01f);
            // m_world->SetGravity(g);

            var world = new World();
            var bodies = new Body[5];
            var joints = new Joint[1];

            {
                BodyDef bd = new BodyDef();
                bd.Type = BodyType.Dynamic;
                bd.Position = new Vector2(-3.580528497695923e-02f, -7.826317548751831e-01f);
                bd.Angle = 8.054048418998718e-01f;
                bd.LinearVelocity = new Vector2(-2.581855468451977e-02f, 0.000000000000000e+00f);
                bd.AngularVelocity = 5.164637044072151e-02f;
                bd.LinearDamping = 0.000000000000000e+00f;
                bd.AngularDamping = 0.000000000000000e+00f;
                bd.AllowSleep = true;
                bd.FixedRotation = false;
                bd.Bullet = true;
                //bd.active = bool(32);
                bd.GravityScale = 1.000000000000000e+00f;
                bodies[3] = world.CreateBody(bd);

                {
                    FixtureDef fd = new FixtureDef();
                    fd.Friction = 2.000000029802322e-01f;
                    fd.Restitution = 2.000000029802322e-01f;
                    fd.Density = 2.000000000000000e+00f;
                    fd.IsSensor = false;
                    fd.Filter.CategoryBits = (1);
                    fd.Filter.MaskBits = (65535);
                    fd.Filter.GroupIndex = (0);
                    CircleShape shape = new CircleShape();
                    shape.Radius = 5.000000000000000e-01f;
                    shape.Center = new Vector2(0.000000000000000e+00f, 0.000000000000000e+00f);

                    fd.Shape = shape;

                    bodies[3].CreateFixture(fd);
                }
            }
            {
                BodyDef bd = new BodyDef();
                bd.Type = BodyType.Static;
                bd.Position = new Vector2(0.000000000000000e+00f, 0.000000000000000e+00f);
                bd.Angle = 0.000000000000000e+00f;
                bd.LinearVelocity = new Vector2(0.000000000000000e+00f, 0.000000000000000e+00f);
                bd.AngularVelocity = 0.000000000000000e+00f;
                bd.LinearDamping = 0.000000000000000e+00f;
                bd.AngularDamping = 0.000000000000000e+00f;
                bd.AllowSleep = true;
                bd.FixedRotation = false;
                bd.Bullet = false;
                //bd.active = bool(32);
                bd.GravityScale = 1.000000000000000e+00f;
                bodies[4] = world.CreateBody(bd);

            }
            {
                DistanceJointDef jd = new DistanceJointDef();
                jd.BodyA = bodies[4];
                jd.BodyB = bodies[3];
                jd.CollideConnected = false;
                jd.LocalAnchorA = new Vector2(4.595311164855957e+00f, -1.409123420715332e+00f);
                jd.LocalAnchorB = new Vector2(4.783708136528730e-03f, 9.254086180590093e-04f);
                jd.Length = 4.671227455139160e+00f;
                jd.FrequencyHz = 0.000000000000000e+00f;
                jd.DampingRatio = 0.000000000000000e+00f;
                joints[0] = world.CreateJoint(jd);
            }

            return world;
        }
    }
}